/**
 *
 */
package anyware.common.json;

import java.util.Date;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonBeanProcessor;

import org.apache.commons.lang.Validate;

/**
 * @author keke<keke@codehaus.org>
 * @version $Revision: 107 $
 */
public class DateBeanProcessor implements JsonBeanProcessor {

    /*
     * (non-Javadoc)
     * 
     * @see net.sf.json.processors.JsonBeanProcessor#processBean(java.lang.Object,
     *      net.sf.json.JsonConfig)
     */
    public JSONObject processBean(final Object bean, final JsonConfig jsonConfig) {
	    Validate.isTrue(bean instanceof Date);
		final JSONObject obj = new JSONObject();
		obj.put("$", ((Date) bean).getTime());
		obj.put("type", bean.getClass().getName());
		return obj;
	}
}
